/******************************************************************************/
/*Files to Include                                                            */
/******************************************************************************/

#if defined(__XC)
    #include <xc.h>         /* XC8 General Include File */
#elif defined(HI_TECH_C)
    #include <htc.h>        /* HiTech General Include File */
#elif defined(__18CXX)
    #include <p18cxxx.h>    /* C18 General Include File */
#endif

#if defined(__XC) || defined(HI_TECH_C)

//include <stdint.h>         /* For uint8_t definition */
//#include <stdbool.h>        /* For true/false definition */
#include "stdtypedef.h"
#include "system.h"
#include "drv_uart.h"
#include "periodic_task_exec.h"
#include "app_io.h"

#endif

/******************************************************************************/
/* Interrupt Routines                                                         */
/******************************************************************************/

/* High-priority service */

#if defined(__XC) || defined(HI_TECH_C)
void interrupt high_isr(void)
#elif defined (__18CXX)
#pragma code high_isr=0x08
#pragma interrupt high_isr
void high_isr(void)
#else
#error "Invalid compiler selection for implemented ISR routines"
#endif

{
    if(TMR1IF){
        extern T_UWORD    ruw_TickCounter;
extern union{
    struct{
        T_UBYTE     ALL;
    }by;
    struct{
        T_UBYTE     _1TCK   :1;
        T_UBYTE     _5TCK   :1;
        T_UBYTE     _10TCK  :1;
        T_UBYTE     _20TCK  :1;
        T_UBYTE     _200TCK :1;
        T_UBYTE     _1kTCK  :1;

        T_UBYTE     NEWTCK  :1;
    }bi;
}rs_TckFlags;

        rs_TckFlags.bi.NEWTCK = 1;
        if(ruw_TickCounter < 1000){
            ruw_TickCounter++;
        }
        else{
            ruw_TickCounter = 0;
        }
        TMR1IF = 0;
        TMR1 = (0xFFFF - MIN_TICK(1));
        return;
    }
//
//    if(RCIF){
//        ls_UartFlags.bi.bit0 = 1;
//        rub_DataReceived = RCREG;
//    }
    if(TXIF && TXIE){
        uart_send_char(rub_TempValue);
        TXIE = 0;
    }

    if(RCIF && RCIE){
        TXIE = 1;
        switch(get_uart()){
            case 'o':
                SET_PIN(RD1);
                break;
            case 'O':
                CLEAR_PIN(RD1);
                break;
            case 'r':
                break;
            default:
                break;
        }
    }
    else{
        
    }
}

//Low-priority interrupt routine
//#if defined(__XC) || defined(HI_TECH_C)
//void low_priority interrupt low_isr(void)
//#elif defined (__18CXX)
//#pragma code low_isr=0x18
//#pragma interruptlow low_isr
//void low_isr(void)
//#else
//#error "Invalid compiler selection for implemented ISR routines"
//#endif
//{
//
//      /* This code stub shows general interrupt handling.  Note that these
//      conditional statements are not handled within 3 seperate if blocks.
//      Do not use a seperate if block for each interrupt flag to avoid run
//      time errors. */
//
//#if 0
//
//      /* TODO Add Low Priority interrupt routine code here. */
//
//      /* Determine which flag generated the interrupt */
//      if(<Interrupt Flag 1>)
//      {
//          <Interrupt Flag 1=0>; /* Clear Interrupt Flag 1 */
//      }
//      else if (<Interrupt Flag 2>)
//      {
//          <Interrupt Flag 2=0>; /* Clear Interrupt Flag 2 */
//      }
//      else
//      {
//          /* Unhandled interrupts */
//      }
//
//#endif
//
//}
